﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Library.Db
{
    public interface IAppDBContext
    {

        #region 事务管理
        /// <summary>
        /// 提交数据库事务
        /// </summary>
        void Commit();

        /// <summary>
        /// 打开数据库事务
        /// </summary>
        void OpenTransaction();

        /// <summary>
        /// 回滚事务
        /// </summary>
        void RollbackChanges();
        #endregion

        /// <summary>
        /// 查
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="sql">SQL</param>
        /// <param name="parameters">参数</param>
        /// <returns></returns>
        IEnumerable<TEntity> Get<TEntity>(string sql, object param = null);

        /// <summary>
        /// 增删改
        /// </summary>
        /// <param name="sql">SQL</param>
        /// <param name="parameters">参数</param>
        /// <returns></returns>
        int ExecuteCommand(string sql, object param = null);

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Insert<T>(T entity, string tableName = "");

        /// <summary>
        /// 提交数据库请求
        /// </summary>
        /// <returns></returns>
        void SaveChanges();

        /// <summary>
        /// 是否被释放
        /// </summary>
        /// <returns></returns>
        bool IsDisposed();

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="conStr"></param>
        /// <param name="strTableName"></param>
        /// <param name="dtData"></param>
        void BulkInsert(string conStr, string strTableName, DataTable dtData);

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="conStr"></param>
        /// <param name="strTableName"></param>
        /// <param name="dtData"></param>
        void BulkInsert<T>(string conStr, string strTableName, List<T> list);
    }
}
